package com.example.demo.service;

import com.example.demo.domain.Filedata;
import com.example.demo.repository.FiledataRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class FiledataServiceImpl implements FiledataService {
    @Autowired
    private FiledataRepository filedataRepository;

    @Override
    public Filedata saveFiledata(Filedata filedata) {
        return filedataRepository.save(filedata);
    }

    @Override
    public void removeFiledata(Filedata filedata) {
        filedataRepository.delete(filedata);
    }

    @Override
    public Filedata updateFiledata(Filedata filedata) {
        return filedataRepository.save(filedata);
    }

    @Override
    public Filedata getFiledataById(Long id) {
        return filedataRepository.getOne(id);
    }

    @Override
    public Filedata getFiledataByFilename(String filename) {
        return filedataRepository.findByFilename(filename);
    }

    @Override
    public Filedata getFiledataByFilehash(String filehash) {
        return filedataRepository.findByFilehash(filehash);
    }

    @Override
    public List<Filedata> getFiledatas() {
        return filedataRepository.findAllByOrderByIdDesc();
    }

    @Override
    public Page<Filedata> listFiledatasByUserid(Long userid, Pageable pageable) {
        return filedataRepository.findByUserid(userid,pageable);
    }
}
